<%--
  @desc: 应用系统角色资源绑定
  @author: chenw
  @create: 2014-5-23 AM 9:36
--%>
<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<style type="text/css">
    .pageFormContent .textInput {
        width: 220px;
    }

    .gray {
        color: gray;
    }

    #res_detail {
        border: 1px solid #ccc;
        height: 55px;
        clear: right;
        text-indent: 5px;
        padding-top: 3px;
    }
</style>
<div class="pageContent">
    <div class="pageFormContent">
        <div style="height: 340px;overflow-y: auto;margin-bottom: 8px;">
            <ul id="sys_res_tree" class="tree treeFolder treeCheck expand">
                <c:forEach var="node" items="${tree}">
                    <li>
                        <a href="#" onclick="bindByParent(${node.id})">${node.text}</a>
                        <ul>
                            <c:forEach var="leaf" items="${node.leaf}">
                                <li class="leaf">
                                    <a href="<c:url value='/sys/resource/bind/${roleId}/${leaf.id}'/>" ${leaf.flag}
                                       tvalue="${leaf.id}" remark="${leaf.remark}">${leaf.name}</a>
                                </li>
                            </c:forEach>
                        </ul>
                    </li>
                </c:forEach>
            </ul>
        </div>
        <div id="res_detail"></div>
    </div>
    <div class="formBar">
        <ul>
            <li>
                <div class="buttonActive">
                    <div class="buttonContent">
                        <button type="button" onclick="saveRoleResource();">保存</button>
                    </div>
                </div>
            </li>
            <li>
                <div class="button">
                    <div class="buttonContent">
                        <button type="button" class="close">取消</button>
                    </div>
                </div>
            </li>
        </ul>
    </div>

</div>
<script type="text/javascript">
    function saveRoleResource() {
        var ids = [];
        $("#sys_res_tree .leaf .ckbox.checked").each(function (index, obj) {
            ids.push($(this).siblings("a").attr("tvalue"));
        });
        $.ajax({
            type: 'post',
            contentType: 'application/json',
            url: '<c:url value='/sys/resource/bind/${roleId}'/>?ids=' + ids.join(),
            processData: false,
            dataType: 'json',
            success: function (resp) {
                if (resp && resp.statusCode == DWZ.statusCode.ok) {
                    alertMsg.info("角色绑定资源信息更新成功");
                } else {
                    alertMsg.error("角色绑定资源信息更新失败");
                }
            }

        });
    }
    $(function () {
        $("#sys_res_tree a").click(function () {
            $("#res_detail").html($(this).attr("remark"));
        });
    });

</script>